<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>内部账号管理</title>
    <link rel="stylesheet" href="css/font-awesome.min.css"/>
    <link rel="stylesheet" href="css/font-awesome-ie7.min.css"/>
    <link rel="stylesheet" href="css/bootstrap.min.css"/>
    <link href="css/jquery.datetimepicker.css" rel="stylesheet">
    <link rel="stylesheet" href="css/admin.css"/>

    <link rel="stylesheet" type="text/css" href="css/paging.css">

    <!--[if lt IE 9]>
    <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <![endif]-->
    <!--[if lt IE 10]>
    <script src="http://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
    <script src="http://cdn.bootcss.com/jquery-placeholder/2.0.8/jquery.placeholder.min.js"></script>
    <![endif]-->
</head>
<body>
<div id="gray_bg"></div>
<!-- 编辑分类开始 -->
<div id="editDiadog" class="diadog">
    <div class="diadog-tit">
        <div class="row">
            <div class="col-md-11 iewidth330"><span>添加内部账户</span></div>
            <div class="col-md-1 close ie8width100"><span>×</span></div>
        </div>
    </div>
    <div class="diadog-con">
        <div class="form-horizontal" role="form">
            <div style="display: none">
                <input id="accountId" type="text" class="form-control">
            </div>
            <div class="form-group" id="useraccount">
                <label for="inputEmail3" class="col-sm-3 control-label"><span
                        style="color: #e4393c">*</span>注册账号:</label>
                <div class="col-sm-9">
                    <input id="account" type="text" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label for="inputPassword3" class="col-sm-3 control-label"><span
                        style="color: #e4393c">*</span>用户姓名:</label>
                <div class="col-sm-9">
                    <input id="username" type="text" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label for="inputPassword3" class="col-sm-3 control-label"><span
                        style="color: #e4393c">*</span>联系电话:</label>
                <div class="col-sm-9">
                    <input id="linkphone" type="text" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label for="inputPassword3" class="col-sm-3 control-label"><span
                        style="color: #e4393c"></span>QQ:</label>
                <div class="col-sm-9">
                    <input id="qq" type="text" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label for="inputPassword3" class="col-sm-3 control-label"><span
                        style="color: #e4393c">*</span>用户类型:</label>
                <div class="col-sm-9">
                        <!-- Split button -->
                        <div class="btn-group">
                            <button type="button" class="btn btn-default" id="typeVal" itemValue="1">推广账号</button>
                            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu" role="menu">
                                <li><a id="1" onclick="typeSearch(this)" href="javascript:;">推广账号</a></li>
                                <li><a id="2" onclick="typeSearch(this)" href="javascript:;">客服账号</a></li>
                                <li><a id="3" onclick="typeSearch(this)" href="javascript:;">产品账号</a></li>
                                <li><a id="4" onclick="typeSearch(this)" href="javascript:;">管理账号</a></li>
                            </ul>
                        </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-4 ml">
                    <button id="addUserSure" type="submit" class="btn btn-primary">确 定</button>
                    <button id="editUserSure" type="submit" class="btn btn-primary">确 定</button>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 编辑分类结束 -->
<!-- 删除分类开始 -->
<div id="deleteDiadog" class="diadog">
    <div class="diadog-tit">
        <div class="row">
            <div class="col-md-11"><span id="delTitle">确定禁用该分类？</span></div>
            <div class="col-md-1 close"><span>×</span></div>
        </div>
    </div>
    <div class="diadog-con" style="padding:30px 0">

        <div class="form-horizontal" role="form">
            <div class="row">
                <div class="col-md-12"></div>

                <div class="form-group" style="text-align: center;">``
                    <div class="col-md-1"></div>
                    <div class="col-md-2">
                        <button id="enableSure" type="submit" class="btn btn-primary">确 定</button>
                    </div>
                    <div class="col-md-2">
                        <button id="btn-default" type="submit" class="btn btn-default">取 消</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 删除分类结束 -->
<!-- 二维码开始 -->
<div id="qrCodeDiadog" class="diadog" style="width: 430px;height: 430px">
    <div class="diadog-tit" style="width:430px;">
        <div class="row">
            <div class="col-md-11" id="diadogqrCodeTitle"><span>二维码</span></div>
            <div class="col-md-1 close"><span>×</span></div>
        </div>
    </div>
    <div class="diadog-con" style="width: 430px;height: 430px">
        <img id="qrCode" src="" alt="">
    </div>
</div>
<!-- 二维码结束 -->
<!-- header start -->
<div id="header" class="header">

</div>
<!-- header end -->
<!-- usercenter start -->
<div class="usercotent">
    <div id="center-left"></div>
    <div class="usercotentr floatr">
        <div class="user-tit" style="margin-bottom:10px">
            <h3>内部账号管理</h3>
        </div>
        <div class="usercotent-con">
            <div class="col-md-12">
                <button id="addCategory" type="button" class="btn btn-danger pull-right">添加内部账号</button>
            </div>
            <div class="down">
                <table id="testMyGrid" class="table table-bordered table-hover"></table>
            </div>
            <!-- page start -->
            <nav class="totalpage floatr">
                <span>总共</span><strong id="totalpage"></strong><span>条</span>
                <div id="pageTool" style="margin-top:20px;"></div>
            </nav>
            <div class="floatl" style="margin-top: 100px">
                <span style="color:#e4393c;font-size: 15px;font-weight: bolder">用户类型</span>
                <p style="line-height: 20px">推广账号：负责小程序的推广和分享；</p>
                <p style="line-height: 20px">客服账号：负责订单的受理、成交等业务；</p>
                <p style="line-height: 20px">产品账号：负责产品的信息、价格维护；</p>
                <p style="line-height: 20px">管理账号：负责产品维护、订单受理等业务；</p>
                <p style="line-height: 20px;color: #00B0F0;">以上所有账号均可绑定过二维码进行小程序的分享和推广。</p>
            </div>
            <div class="clear"></div>
            <!-- page end -->

        </div>

    </div>
    <div class="clear"></div>
</div>

<!-- usercenter end -->

<!-- footer start -->
<div class="footer">
    <div class="bot">
        <p style="padding-top: 10px; text-align: center">Copyright (C) 都能印 2014-2016, all Rights Reserved |
            豫ICP备14024464号-1 | 增值电信业务经营许可证：豫B2-20150019</p>
        <p class="authentication" style="padding-bottom: 10px; padding-top: 10px;">
            <img src="img/footer1.png" alt="">
            <img src="img/footer2.png" alt="">
            <img src="img/footer3.png" alt="">
            <img src="img/footer4.png" alt="">
            <img src="img/footer5.png" alt="">
        </p>
    </div>
</div>
<!-- footer end -->
<script src="js/jquery.min-1-11-3.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/widget/myDataGrid.js"></script>
<script src="js/widget/admin.js"></script>
<script type="text/javascript" src="js/query.js"></script>
<script type="text/javascript" src="js/paging.js"></script>
<script type="text/javascript" src="bower_components/plupload/js/plupload.full.min.js"></script>
<script type="text/javascript" src="js/ui.js"></script>
<script type="text/javascript" src="js/qiniu.min.js"></script>
<script type="text/javascript" src="js/upload.js"></script>
<script type="text/javascript">
    var id;
    //开始
    $(function () {
        initSideAccMenu("内容管理", "内部账号列表");
//        获取数据

        var dataArray = [
            {attribute: 'partnerId', attributeValue: query("partnerId")}
        ]
        $("#testMyGrid").grid({
            id: "testMyGrid",
            pageTotalId: "totalpage",
            pageToolId: "pageTool",
            url: "apis/user/getloginuserpagelist",
            columns: [
                { field: 'account', title: '注册账号', conmethod: 'getNullStr', calcfield:'', kind:'', region:0},
                { field: 'userName', title: '用户姓名', conmethod: 'getNullStr', calcfield:'', kind:'', region:0},
                { field: 'usertype', title: '用户类型', conmethod: 'getUserType', calcfield:'', kind:'', region:1},
                { field: 'linkmanPhone', title: '联系电话', conmethod: 'getNullStr', calcfield:'', kind:'', region:0},
                { field: 'id', title: '操作', conmethod: 'getUserOptURL', calcfield:'', kind:'', region:1}
            ],
            InitializationData: dataArray,
            pagesize: 10
        });
    });
    function getUserType() {
        var user = arguments[1];
        var shtml = "";
        if(user.usertype == 1){
            shtml = "<span>推广账号</span>"
        }else if(user.usertype == 2){
            shtml = "<span>客服账号</span>"
        }else if(user.usertype == 3){
            shtml = "<span>产品账号</span>"
        }else{
            shtml = "<span>管理账号</span>"
        }
        return shtml;
    }
//    操作
    function getUserOptURL() {
        var user = arguments[1];
        var shtml = "";
        if (user.enabled == 1) {
            shtml += "<a onclick=\"toEdit(" + user.userid + ",'" + user.userName + "','" + user.linkmanPhone + "','" + user.linkmanQQ + "'," + user.usertype + ")\"" + " href=\"javascript:;\">编辑</a>";
            shtml += "&nbsp&nbsp&nbsp";
            shtml += "<a onclick=\"toEnable(" + user.userid + ",0)\"" + " href=\"javascript:;\">禁用</a>";
            shtml += "&nbsp&nbsp&nbsp";
            shtml += "<a onclick=\"toReset('" + user.account + "')\"" + " href=\"javascript:;\">重置密码</a>";
            shtml += "&nbsp&nbsp&nbsp<br>";
            shtml += "<a onclick=\"toBindwxacode(" + user.userid + ")\"" + " href=\"javascript:;\">绑定二维码</a>";
            shtml += "&nbsp&nbsp&nbsp";
            shtml += "<a onclick=\"toSharexacode(" + user.userid + ")\"" + " href=\"javascript:;\">分享推广二维码</a>";
        } else {
            shtml += "<a style='color: red' deptname=\"" + user.deptname + "\">已禁用</a>";
            shtml += "&nbsp&nbsp&nbsp&nbsp";
            shtml += "<a onclick=\"toEnable(" + user.userid + ",1)\">点击启用</a>";
        }
        return shtml;
    }

    function typeSearch(e) {
        $("#typeVal").html($(e).html());
        $("#typeVal").attr("itemValue",$(e).attr("id"));
    }

//    编辑
    var userID;
    function toEdit(id, username, phone, qq,usertype) {
        userID = id;
        $("#gray_bg").show();
        $("#gray_bg").css({"height": $(document).height()});
        $("#editDiadog").show();
        $("#editDiadog").center();
        $("#addUserSure").hide();
        $("#editUserSure").show();
        $("#useraccount").hide();

        if (qq == null || qq == "undefined" || qq == "") {
            var qqnum = "";
        } else {
            var qqnum = qq;
        }
        $("#username").val(username);
        $("#linkphone").val(phone);
        $("#qq").val(qqnum);
        $("#typeVal").attr("itemValue",usertype);
        if(usertype == 1){
            $("#typeVal").html("推广账号")
        }else if(usertype == 2){
            $("#typeVal").html("客服账号")
        }
        else if(usertype == 3){
            $("#typeVal").html("产品账号")
        }
        else{
            $("#typeVal").html("管理账号")
        }
    }
    $("#editUserSure").click(function () {
        if ($("#username").val() == "") {
            alert("用户姓名不能为空");
            return;
        }
        if ($("#linkphone").val() == "") {
            alert("联系电话不能为空");
            return;
        }
        var data = {
            userid:userID,
            userName:$("#username").val(),
            linkmanPhone:$("#linkphone").val(),
            linkmanQQ:$("#qq").val(),
            usertype:$("#typeVal").attr("itemValue")
        }
        $.ajax({
            url: "apis/user/updateloginuser",
            type: 'post',
            data: {
                "user": JSON.stringify(data)
            },
            dataType: 'json',
            success: function (data, status, xhr) {
                if (data.httpCode == 200) {
                    $("#gray_bg").hide();
                    $("#editDiadog").hide();
                    window.location.reload();
                } else {
                    alert(data.msg);
                }
            }
        });

    });
//    禁用
    var enable;
    function toEnable(id, e) {
        userID = id;
        enable = e;
        $("#gray_bg").show();
        $("#gray_bg").css({"height": $(document).height()});
        $("#deleteDiadog").show();
        $("#deleteDiadog").center();
        if (e == 1) {
            $("#delTitle").html("确定启用该用户？");
        } else {
            $("#delTitle").html("确定禁用该用户？");
        }
    }
    $("#enableSure").click(function () {
        var data = {
            userid: userID,
            enabled: enable
        };
        var url = "apis/user/updateloginuserenable";
        $.ajax({
            url: url,
            type: 'post',
            data: {
                "user": JSON.stringify(data)
            },
            dataType: 'json',
            success: function (data, status, xhr) {
                if (data.httpCode == 200) {
                    $("#gray_bg").hide();
                    $("#deleteDiadog").hide();
                    window.location.reload();
                } else {
                    alert(data.msg);
                }
            }
        });
    })
//    添加用户
    $("#addCategory").click(function () {
        $("#gray_bg").show();
        $("#gray_bg").css({"height": $(document).height()});
        $("#editDiadog").show();
        $("#editDiadog").center();
        $("#addUserSure").show();
        $("#editUserSure").hide();
        $("#useraccount").show();
    })
    $("#addUserSure").click(function () {
        if ($("#account").val() == "") {
            alert("注册账号不能为空");
            return;
        }
        if ($("#username").val() == "") {
            alert("用户姓名不能为空");
            return;
        }
        if ($("#linkphone").val() == "") {
            alert("联系电话不能为空");
            return;
        }
        var account = $("#account").val();
        var username = $("#username").val();
        var linkphone = $("#linkphone").val();
        var qq = $("#qq").val();
        var data = {
//            partnerId: query("partnerId"),
            account:account,
            userName:username,
            linkmanPhone:linkphone,
            linkmanQQ:qq,
            usertype:$("#typeVal").attr("itemValue")
        }

        $.ajax({
            url: "apis/user/addloginuser",
            type: 'post',
            data: {
                "user": JSON.stringify(data)
            },
            dataType: 'json',
            success: function (data, status, xhr) {
                if (data.httpCode == 200) {
                    $("#gray_bg").hide();
                    $("#editDiadog").hide();
                    window.location.reload();
                } else {
                    alert(data.msg);
                }
            }
        })
    })
//    绑定二维码
    function toBindwxacode(id) {
        $.ajax({
            url: "apis/user/getloginuserbindwxacode",
            type: 'post',
            data: {
                "userId": id
            },
            dataType: 'json',
            success: function (data, status, xhr) {
                if (data.httpCode == 200) {
                    $("#gray_bg").show();
                    $("#gray_bg").css({"height": $(document).height()});
                    $("#qrCodeDiadog").center();
                    $("#qrCodeDiadog").show();
                    $("#qrCode").attr("src", "apis" + data.data + "");
                } else {
                    alert(data.msg);
                }
            }
        })
    }
//    推广二维码
    function toSharexacode(id) {
        $.ajax({
            url: "apis/user/getloginusersharewxacode",
            type: 'post',
            data: {
                "userId": id
            },
            dataType: 'json',
            success: function (data, status, xhr) {
                if (data.httpCode == 200) {
                    $("#gray_bg").show();
                    $("#gray_bg").css({"height": $(document).height()});
                    $("#qrCodeDiadog").center();
                    $("#qrCodeDiadog").show();
                    $("#qrCode").attr("src", "apis" + data.data + "");
                } else {
                    alert(data.msg);
                }
            }
        })
    }
//    重置密码
    function toReset(account) {
        $.ajax({
            url: "apis/user/resetloginuserpassword",
            type: 'post',
            data: {
                account: account
            },
            dataType: 'json',
            success: function (data, status, xhr) {
                if (data.httpCode == 200) {
                    alert("密码重置成功，将在下次登录时生效");
                } else {
                    alert(data.msg);
                }
            }
        })
    }
    //垂直居中
    jQuery.fn.center = function () {
        this.css("position", "absolute");
        this.css("top", ( $(window).height() - this.height() ) / 2 + $(window).scrollTop() + "px");
        this.css("left", ( $(window).width() - this.width() ) / 2 + $(window).scrollLeft() + "px");
        return this;
    }
    function query(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null)return unescape(r[2]);
        return "";
    }
    $(".close,#btn-default").click(function () {
        $("#gray_bg").hide();
        $("#editDiadog").hide();
        $("#deleteDiadog").hide();
        $("#qrCodeDiadog").hide();

        $("#account").val("");
        $("#username").val("");
        $("#linkphone").val("");
        $("#qq").val("");
    })
</script>
</body>
</html>